<?php
/** Zend_Controller_Action */ 
require_once APPLICATION_PATH . '/../library/Soooner/Controller/Action.php';
class LvsvipController extends Soooner_Controller_Action
{
	private $_id;
	private $_modelLvsvip;
	private $_modelLvsdatacenter;
	private $_lbalgos = array("rr"=>"rr","wrr"=>"wrr","lc"=>"lc","wlc"=>"wlc","lblc"=>"lblc","lblcr"=>"lblcr","dh"=>"dh","sh"=>"sh");//调度算法
    private $_lbkinds = array("DR"=>"DR","NAT"=>"NAT","TUN"=>"TUN");
	private $_protocols = array("TCP"=>"TCP","UDP"=>"UDP");
	private $_usetypes = array("REAL"=>"直播设备组","REALVOD"=>"点播设备组","REALTS"=>"时移设备组","PROXY"=>"直播代理组","PROXYVOD"=>"点播代理组","PROXYTS"=>"时移代理组");
    public function init()
    {
        /* Initialize action controller here */
    	$this->initDzTemplate();
    	$this->_modelLvsvip = new Model_Tables_Lvsvip();
    	$this->_modelLvsdatacenter = new Model_Tables_Lvsdatacenter();
    }
    /**
    * 获取虚拟IP池列表
    * @return unknown_type
    */
    public function indexAction()
    {
    	/*$options = $GLOBALS['application']->getOptions();
    	$numPerPage = $options["pagecount"];//每页显示的条数
        $ItemCount =  $this->_modelLvsvip->getCount();
        $PageCount = ceil($ItemCount/$numPerPage);
        $PageCount = $PageCount ? $PageCount : 1;*/
		include $this->_dzTemplate->getFile( 'lvsvip.manage.html' );
    }
    /**
    * 获取虚拟IP池列表
    * @return unknown_type
    */
    public function indexajaxAction()
    {
        $options = $GLOBALS['application']->getOptions();
    	$numPerPage = $options["pagecount"];//每页显示的条数
        $page = intval($this->_getParam('page'));//默认页码
        $page = empty($page)?'1':$page;
   		$s = $this->_getParam('s'); 
        $ItemCount =  $this->_modelLvsvip->getCount($s);
        $PageCount = ceil($ItemCount/$numPerPage);
        if($page>$PageCount)$page=$PageCount;
        $infos0 = $this->_modelLvsvip->getList( $page, $numPerPage, $s );
        foreach($infos0 as $info){
        	$info["usetype"]=$this->_usetypes[$info["usetype"]];
        	$infos[]=$info;
        }
        include $this->_dzTemplate->getFile( 'ajax/lvsvip.manage.ajax.html' );
    }
    /**
    * 添加虚拟IP池
    * @return unknown_type
    */
    public function addAction()
    {
    	$datacenters = $this->_modelLvsdatacenter->getCenters();
    	$lbalgos = $this->_lbalgos;
    	$lbkinds = $this->_lbkinds;
    	$protocols = $this->_protocols;
    	$usetypes = $this->_usetypes;
    	$request = $this->getRequest();        
        if ($request->isPost())
        {
            $params =$request->getPost();
            $this->_modelLvsvip->add($params);                
            $this->_redirect("/lvsvip/index/");
        } 
        include $this->_dzTemplate->getFile( 'lvsvip.add.html' );
    }
    /**
    * 修改虚拟IP池
    * @return unknown_type
    */
    public function modifyAction()
    {
    	$datacenters = $this->_modelLvsdatacenter->getCenters();
    	$lbalgos = $this->_lbalgos;
    	$lbkinds = $this->_lbkinds;
    	$protocols = $this->_protocols;
    	$usetypes = $this->_usetypes;
    	$id = $this->_getParam('id');
    	$info = $this->_modelLvsvip->getInfo($id); 
        $request = $this->getRequest();        
        if ($request->isPost())
        {
        	$request =$request->getPost();        	
            if (true)//服务端检查输入参数
            {
                $this->_modelLvsvip->modify($request,$id);
                $this->_redirect("/lvsvip/");
            }
        } 
        include $this->_dzTemplate->getFile( 'lvsvip.edit.html' );
    }
    /**
    * 无刷新修改虚拟IP池
    * @return unknown_type
    */    
    public function modifyajaxAction()
    {
        $request = $this->getRequest();
        $params = $request->getPost();
        $arr = split("\|", $params['id']);
        $field = $arr[0];
        $id = $arr[1];
        $value = stripslashes($params['value']);
        $this->_modelLvsvip->modifyAjax($id,$field,$value);
        echo $value;
        exit;
    }
    public function modifyajaxreversAction()
    {
    	$field = $this->_getParam('field');
    	$pri = $this->_getParam('pri');
        $this->_modelLvsvip->modifyAjaxRevers($field,$pri);
        exit;
    }
    /**
    * 删除虚拟IP池
    */
    public function deleteAction()
    {
        $id = $this->_getParam('id');   
        $this->_modelLvsvip->del($id); 
        exit;
    }
}
